SPB Git

Repository Public

route.ts 3.1 KB 80 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SPB Private Cloud8 * File             : app/api/shared-spaces/[id]/members/route.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/spb-cloud11 * Project Website  : https://cloud.spboucher.ai12 * Created          : 2026-02-2113 * Last Modified    : 2026-02-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { NextRequest, NextResponse } from "next/server";43import { getIronSession } from "iron-session";44import { SessionData, sessionOptions } from "@/lib/session";45import { prisma } from "@/lib/prisma";46import { requireAdmin } from "@/lib/auth";4748export async function POST(request: NextRequest, { params }: { params: { id: string } }) {49  const response = NextResponse.next();50  const session = await getIronSession<SessionData>(request, response, sessionOptions);51  if (!session.userId || !(await requireAdmin(session.userId))) {52    return NextResponse.json({ error: "Forbidden" }, { status: 403 });53  }5455  const { userId } = await request.json();56  if (!userId) return NextResponse.json({ error: "userId requis" }, { status: 400 });5758  const member = await prisma.sharedSpaceMember.create({59    data: { sharedSpaceId: params.id, userId },60    include: { user: { select: { id: true, name: true, username: true } } },61  });6263  return NextResponse.json(member, { status: 201 });64}6566export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {67  const response = NextResponse.next();68  const session = await getIronSession<SessionData>(request, response, sessionOptions);69  if (!session.userId || !(await requireAdmin(session.userId))) {70    return NextResponse.json({ error: "Forbidden" }, { status: 403 });71  }7273  const { userId } = await request.json();74  await prisma.sharedSpaceMember.deleteMany({75    where: { sharedSpaceId: params.id, userId },76  });7778  return NextResponse.json({ success: true });79}80
Files main
Menu

Theme